package androidx.appcompat.view.menu;

import android.content.Context;
import android.os.Bundle;
import android.os.Parcelable;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import java.util.ArrayList;
import o.ah$j;
import o.bd;
import o.bj;
import o.bk;
import o.bn;
import o.bo;
import o.bo.b;
import o.bv;

@RestrictTo({d.LIBRARY_GROUP})
public class ListMenuPresenter implements bn, OnItemClickListener {
    MenuAdapter ʻ;
    int ʼ;
    int ʽ;
    ExpandedMenuView ˊ;
    bd ˋ;
    LayoutInflater ˎ;
    int ˏ;
    Context ॱ;
    private int ॱॱ;
    private bn.d ᐝ;

    class MenuAdapter extends BaseAdapter {
        private int mExpandedIndex = -1;

        public MenuAdapter() {
            findExpandedIndex();
        }

        public int getCount() {
            int size = ListMenuPresenter.this.ˋ.ॱˊ().size() - ListMenuPresenter.this.ˏ;
            return this.mExpandedIndex < 0 ? size : size - 1;
        }

        public bj getItem(int i) {
            ArrayList ॱˊ = ListMenuPresenter.this.ˋ.ॱˊ();
            int i2 = ListMenuPresenter.this.ˏ + i;
            if (this.mExpandedIndex >= 0 && i2 >= this.mExpandedIndex) {
                i2++;
            }
            return (bj) ॱˊ.get(i2);
        }

        public long getItemId(int i) {
            return (long) i;
        }

        public View getView(int i, View view, ViewGroup viewGroup) {
            View inflate;
            if (view == null) {
                inflate = ListMenuPresenter.this.ˎ.inflate(ListMenuPresenter.this.ʼ, viewGroup, false);
            } else {
                inflate = view;
            }
            ((b) inflate).ॱ(getItem(i), 0);
            return inflate;
        }

        void findExpandedIndex() {
            bj ॱˎ = ListMenuPresenter.this.ˋ.ॱˎ();
            if (ॱˎ != null) {
                ArrayList ॱˊ = ListMenuPresenter.this.ˋ.ॱˊ();
                int size = ॱˊ.size();
                for (int i = 0; i < size; i++) {
                    if (((bj) ॱˊ.get(i)) == ॱˎ) {
                        this.mExpandedIndex = i;
                        return;
                    }
                }
            }
            this.mExpandedIndex = -1;
        }

        public void notifyDataSetChanged() {
            findExpandedIndex();
            super.notifyDataSetChanged();
        }
    }

    public ListMenuPresenter(Context context, int i) {
        this(i, 0);
        this.ॱ = context;
        this.ˎ = LayoutInflater.from(this.ॱ);
    }

    public ListMenuPresenter(int i, int i2) {
        this.ʼ = i;
        this.ʽ = i2;
    }

    public void ˏ(Context context, bd bdVar) {
        if (this.ʽ != 0) {
            this.ॱ = new ContextThemeWrapper(context, this.ʽ);
            this.ˎ = LayoutInflater.from(this.ॱ);
        } else if (this.ॱ != null) {
            this.ॱ = context;
            if (this.ˎ == null) {
                this.ˎ = LayoutInflater.from(this.ॱ);
            }
        }
        this.ˋ = bdVar;
        if (this.ʻ != null) {
            this.ʻ.notifyDataSetChanged();
        }
    }

    public bo ˎ(ViewGroup viewGroup) {
        if (this.ˊ == null) {
            this.ˊ = (ExpandedMenuView) this.ˎ.inflate(ah$j.ʼ, viewGroup, false);
            if (this.ʻ == null) {
                this.ʻ = new MenuAdapter();
            }
            this.ˊ.setAdapter(this.ʻ);
            this.ˊ.setOnItemClickListener(this);
        }
        return this.ˊ;
    }

    public ListAdapter ˊ() {
        if (this.ʻ == null) {
            this.ʻ = new MenuAdapter();
        }
        return this.ʻ;
    }

    public void ˊ(boolean z) {
        if (this.ʻ != null) {
            this.ʻ.notifyDataSetChanged();
        }
    }

    public void ˎ(bn.d dVar) {
        this.ᐝ = dVar;
    }

    public boolean ˎ(bv bvVar) {
        if (!bvVar.hasVisibleItems()) {
            return false;
        }
        new bk(bvVar).ˊ(null);
        if (this.ᐝ != null) {
            this.ᐝ.ˎ(bvVar);
        }
        return true;
    }

    public void ˏ(bd bdVar, boolean z) {
        if (this.ᐝ != null) {
            this.ᐝ.ॱ(bdVar, z);
        }
    }

    public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
        this.ˋ.ˊ(this.ʻ.getItem(i), this, 0);
    }

    public boolean ˏ() {
        return false;
    }

    public boolean ˏ(bd bdVar, bj bjVar) {
        return false;
    }

    public boolean ˎ(bd bdVar, bj bjVar) {
        return false;
    }

    public void ˊ(Bundle bundle) {
        SparseArray sparseArray = new SparseArray();
        if (this.ˊ != null) {
            this.ˊ.saveHierarchyState(sparseArray);
        }
        bundle.putSparseParcelableArray("android:menu:list", sparseArray);
    }

    public void ˏ(Bundle bundle) {
        SparseArray sparseParcelableArray = bundle.getSparseParcelableArray("android:menu:list");
        if (sparseParcelableArray != null) {
            this.ˊ.restoreHierarchyState(sparseParcelableArray);
        }
    }

    public int ॱ() {
        return this.ॱॱ;
    }

    public Parcelable ʽ() {
        if (this.ˊ == null) {
            return null;
        }
        Bundle bundle = new Bundle();
        ˊ(bundle);
        return bundle;
    }

    public void ˏ(Parcelable parcelable) {
        ˏ((Bundle) parcelable);
    }
}
